package  
{
	import flash.display.MovieClip;
	import flash.events.KeyboardEvent;
	/**
	 * ...
	 * @author ...
	 */
	public class Menu extends Level_Base 
	{
		var turretMenu:Turret;
		var btPlay:MovieClip;
		var btTuto:MovieClip;
		var fundoMenu:MovieClip;
		
		public override function start(): void 
		{
			turretMenu = new Turret();
			turretMenu.x = Main.instance.stage.stageWidth / 2;
			turretMenu.y = Main.instance.stage.stageHeight / 2;
			Main.instance.MC_tela.addChild(turretMenu);
			
			fundoMenu = new FundoMenu();
			fundoMenu.x = fundoMenu.width/2;
			fundoMenu.y = fundoMenu.height/2;
			Main.instance.MC_tela.addChild(fundoMenu);
			
			btPlay = new BotaoPlay();
			btPlay.x = Main.instance.stage.stageWidth / 4;
			btPlay.y = Main.instance.stage.stageHeight / 4;
			Main.instance.MC_tela.addChild(btPlay);
			
			btTuto = new BotaoTutorial();
			btTuto.x = Main.instance.stage.stageWidth*3/4;
			btTuto.y = Main.instance.stage.stageHeight*3/4;
			Main.instance.MC_tela.addChild(btTuto);
		}
		
		public function iniciarLevel(evento: KeyboardEvent):void
		{
			LevelManager.current = new Level1();
		}
		public override function update() 	: void 
		{
			turretMenu.update(new ParedeManager());
			
			for (var i:int = 0; i < turretMenu.tiroManager.AR_tiros.length;i++ ) {
				if (btPlay.hitTestObject(turretMenu.tiroManager.AR_tiros[i])) {
					
					trace("quantidade de tiros " + turretMenu.tiroManager.AR_tiros.length)
					
					for (var j:int = turretMenu.tiroManager.AR_tiros.length - 1; j >= 0; j-- ) {
						trace("deletando tiro " + j);
						Main.instance.MC_tela.removeChild(turretMenu.tiroManager.AR_tiros[j]);
						turretMenu.tiroManager.AR_tiros.splice(j, 1);
					}
					
					LevelManager.current = new Level1();
				}
			}
			
		}
		
		public override function terminate() : void
		{
			Main.instance.MC_tela.removeChild(turretMenu);
			Main.instance.MC_tela.removeChild(fundoMenu);
			Main.instance.MC_tela.removeChild(btPlay);
			Main.instance.MC_tela.removeChild(btTuto);
			
		}
		
	}

}